<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!--用taglib指令完成对JSTL核心标签库的声明 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<link rel="icon" href="${pageContext.request.contextPath}/images/favicon.ico" type="image/x-icon">
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>梦幻蛋糕坊</title>

    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<!-- In index.jsp, replace the header section with this code -->
<div class="top-left">
    在线人数: <strong>${applicationScope.onlineCount != null ? applicationScope.onlineCount : 0}</strong>
</div>
<div class="header">
    <h1>梦幻蛋糕坊</h1>
    <p>用梦幻色彩点缀您的甜蜜时光</p>
    <!-- Add user authentication check -->
    <c:choose>
        <c:when test="${sessionScope.user != null}">
            <p>欢迎您, ${sessionScope.user.username}!
               <a href="logout">退出登录</a></p>
        </c:when>
        <c:otherwise>
            <p><a href="login.jsp">登录</a> | <a href="register.jsp">注册</a></p>
        </c:otherwise>
    </c:choose>
</div>

<div class="cart-container">
    <h3 style="color: #5a5a8a;"><a href="showcart.jsp">购物车</a>
        <span id="cartTotal" class="cart-count">
           ${cart != null ? cart.amount : 0}
        </span></h3>
    <div id="cartItems" class="cart-items"></div>
</div>

<div class="cakes-container">
    <c:forEach var="cake" items="${cakes}">
        <div class="cake-card">
            <form action="cartServlet?opt=add&id=${cake.id}" method="post">
                <img src="${cake.imageUrl}" alt="${cake.description}" class="cake-image">
                <div class="cake-info">
                    <h3 class="cake-title">${cake.name}</h3>
                    <p class="cake-price">¥${cake.price}</p>
                    <div class="quantity-control">
                        <input type="number" id="cake${cake.id}" name="num" class="quantity-input" value="1" min="1">
                    </div>
                    <button type="submit" class="add-to-cart">加入购物车</button>
                </div>
            </form>
        </div>
    </c:forEach>
</div>
</body>
</html>
